package com.example.domain;

import java.util.List;
//分页查询结果封装
public class PageResult<T> {
    private List<T> rows;       // 当前页数据
    private int pageNum;        // 当前页码
    private int pageSize;       // 每页记录数
    private int totalPages;     // 总页数
    private int totalCount;     // 总记录数

    // 完整参数的构造方法
    public PageResult(List<T> rows, int totalCount, int pageNum, int pageSize) {
        this.rows = rows;
        this.totalCount = totalCount;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.totalPages = (int) Math.ceil((double) totalCount / pageSize);
    }

    // Getters 和 Setters
    public List<T> getRows() {
        return rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        // 更新总页数
        if (totalCount > 0) {
            this.totalPages = (int) Math.ceil((double) totalCount / pageSize);
        }
    }

    public int getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        // 更新总页数
        if (pageSize > 0) {
            this.totalPages = (int) Math.ceil((double) totalCount / pageSize);
        }
    }
}